package com.lsa.letcode.the80.removeDuplicatesSortedArr;

import java.util.Arrays;

import org.junit.Assert;
import org.junit.Test;

public class Remove3orMoreDuplicatesFromSrtTest {
	@Test
	public void test() {
		Solution s = new Solution();
		test(s, new int[] { 1, 1 }, new int[] { 1, 1});
		test(s, new int[] { 1, 1, 1 }, new int[] { 1, 1});
		test(s, new int[] { 1, 1, 1, 1, 1 }, new int[] { 1, 1});
		test(s, new int[] { 1, 2, 3 }, new int[] { 1, 2, 3 });
		test(s, new int[] { 1, 2, 2, 3, 3, 3, 3 }, new int[] { 1, 2, 2, 3, 3 });
		test(s, new int[] { 1, 1, 2, 2, 2, 2, 3, 3, 3, 3 }, new int[] { 1, 1, 2, 2, 3, 3 });
		test(s, new int[] { 1, 1, 2, 2, 3, 3 }, new int[] { 1, 1, 2, 2, 3, 3 });
		test(s, new int[] { 1, 1, 2, 3 }, new int[] { 1, 1, 2, 3 });
		test(s, new int[] { 1, 1, 1, 2, 3 }, new int[] { 1, 1, 2, 3 });
		test(s, new int[] { 1, 2, 2, 3 }, new int[] { 1, 2, 2, 3 });
		test(s, new int[] { 1, 2, 2, 2, 3 }, new int[] { 1, 2, 2, 3 });
		test(s, new int[] { 1, 2, 3, 3 }, new int[] { 1, 2, 3, 3 });
		test(s, new int[] { 1, 2, 3, 3, 3 }, new int[] { 1, 2, 3, 3 });
	}

	private void test(Solution s, int[] input,
			int[] expected) {
		int[] pLen = {0};
		int[] processed = s.removeDuplicatesArr(input, pLen);
		int[] subarray = subArray(processed, pLen[0]);
		Assert.assertTrue(
				String.format("expected %s actual %s",
						Arrays.toString(expected), Arrays.toString(subarray)),
				Arrays.equals(expected, subarray));
		Assert.assertEquals(subarray.length, pLen[0]);
	}
	
	private static int[] subArray(int[] arr, int len) {
		int[] ret = new int[len];
		System.arraycopy(arr, 0, ret, 0, len);
		return ret;
	}
}
